package com.sudu.dao;

import com.sudu.domain.Cation;
import com.sudu.domain.Communication;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CationDao {
    @Insert(" insert into t_communication " +
            "(user_id ,content,create_time,talk_id)" +
            " values (#{userId},#{content},#{createTime},#{talkId});")
    int saveCation(Communication communication );

    @Insert(" insert into t_communication " +
            "(user_id ,create_time,talk_id , connection )" +
            " values (#{userId},#{createTime},#{talkId} , #{connection});")
    int saveCationFirst(Communication communication );

    @Select("select cation_id from  t_communication where user_id = #{uid} and talk_id = #{tid} and is_delete = 1 and connection = 0 limit 0 , 1")
    Cation ifConnection(int uid , int tid) ;

    @Update("update t_communication set is_delete = 0 where cation_id = #{cation} and is_delete = 1  and connection = 0 ")
    int deleteConnection(int cation) ;
    @Select("select user_id , create_time , is_click , content ,talk_id , cation_id from t_communication where " +
            "((user_id = #{uid} and talk_id = #{tid} ) or ( user_id = #{tid} and talk_id = #{uid} ) ) and connection = 1 order by cation_id desc limit #{page},#{pageSize}")
    List<Communication> getCommunications(int uid , int tid , int page , int pageSize) ;

    @Select("select talk_id from t_communication where user_id = #{uid}  and connection = 0 and is_delete = 1 order by  cation_id desc limit 0 ,15 ")
    List<Cation> getTidByUid(int uid) ;

    @Select("select user_id from t_communication where talk_id = #{uid}  and connection = 0 and is_delete = 1 order by  cation_id desc limit 0 ,15 ")
    List<Cation> getTalkCation(int uid) ;


}
